﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Interfaces;

namespace Core.Domains
{
    public class Customer : ICustomer
    {
        private string _adress = "";
        private string _telephone="";
        private string _type;
        protected bool _fromDB;
        private int _customerId;


        public int CustomerID
        {
            get { return _customerId; }
            set { _customerId = value; }
        }

        public string Address
        {
            get { return _adress; }
            set { _adress = value; }
        }

        public string Telephone
        {
            get { return _telephone;}
            set { _telephone = value; }
        }

        public string Type
        {
            get { return _type == "priv" ? "Частное лицо":"Юридическое лицо"; }
        }

        public bool IsPrivate()
        {
            return _type == "priv";
        }

        public Customer()
        {}
     

        public virtual void ConstructIt(object[] Record)
        {
            _customerId = int.Parse(Record[0].ToString());
            _adress = Record[1].ToString();
            _telephone = Record[2].ToString();
            _type = Record[3].ToString();
            _fromDB = true;
        }

        public bool FromDatabase()
        {
            
            return _fromDB; 
        }

        public string GetErrorByCode(int code)
        {
            if (code == 1451 || code ==547)
            {
                return "У данного покупателя есть приобретенные здания";
            }
            return "";
        }

        public void ToJuragial()
        {
            _type = "org";
        }

        public override string ToString()
        {
            return Type + "/" + _telephone;
        }
    }
}
